package com.gimi.cloud.bbp.manage.consumer.service.sys.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.sys.SysMenuDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.SystemFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.sys.SysMenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 菜单相关Consumer
 *
 * @author wbj
 * @version 1.0
 * @Description
 * @create 2018-01-25
 **/
@Service
public class SysMenuServiceImpl implements SysMenuService{
    private static final Logger logger = LoggerFactory.getLogger(SysMenuServiceImpl.class);
    private SystemFeignService systemFeignService;

    @Autowired
    public SysMenuServiceImpl(SystemFeignService systemFeignService) {
        this.systemFeignService = systemFeignService;
    }

    @Override
    public Response getMenuTree(HttpServletRequest request, HttpServletResponse response, SysMenuDTO menuDTO) {
        return systemFeignService.getMenuTree(menuDTO);
    }

    @Override
    public Response getMenuInfo(HttpServletRequest request, HttpServletResponse response, SysMenuDTO menuDTO) {
        if(null == menuDTO.getMeId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"菜单id为空，获取菜单信息失败");
            return resp;
        }
        return systemFeignService.getMenu(menuDTO);
    }


    @Override
    public Response addMenu(HttpServletRequest request, HttpServletResponse response, SysMenuDTO menuDTO) {
        if(null != menuDTO.getMeId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"菜单Id不为空，添加菜单信息失败");
            return resp;
        }
        return systemFeignService.saveMenu(menuDTO);
    }

    @Override
    public Response editMenu(HttpServletRequest request, HttpServletResponse response, SysMenuDTO menuDTO) {
        if(null == menuDTO.getMeId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"菜单Id为空，更新菜单信息失败");
            return resp;
        }
        return systemFeignService.saveMenu(menuDTO);
    }

    @Override
    public Response deleteMenu(HttpServletRequest request, HttpServletResponse response, SysMenuDTO menuDTO) {
        if(null == menuDTO.getMeId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"菜单Id为空，删除菜单信息失败");
            return resp;
        }
        return systemFeignService.deleteMenu(menuDTO);
    }
}
